﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace iLangl.Model
{
	public class BillingInfoResponseContext : BaseResponseContext
	{
		BillingInfo billingInfo = null;

		public override void SetContext(object context)
		{
			base.SetContext(context);

			if (document == null)
				return;

			XmlNode nodebi = document.SelectSingleNode("//BillingInfo");
			

			if (nodebi == null)
				return;
			
			billingInfo = new BillingInfo();

			ParseExtendedInfo(nodebi, billingInfo);

			if (nodebi.Attributes["billingId"] != null)
			{
				billingInfo.Id = nodebi.Attributes["billingId"].Value;
			}

			if (nodebi.Attributes["billingCity"] != null)
			{
				billingInfo.BillingCity = nodebi.Attributes["billingCity"].Value;
			}

			if (nodebi.Attributes["billingCountry"] != null)
			{
				billingInfo.BillingCountry = nodebi.Attributes["billingCountry"].Value;
			}

			if (nodebi.Attributes["billingCurrency"] != null)
			{
				billingInfo.BillingCurrency = nodebi.Attributes["billingCurrency"].Value;
			}

			if (nodebi.Attributes["billingEmail"] != null)
			{
				billingInfo.BillingEmail = nodebi.Attributes["billingEmail"].Value;
			}

			if (nodebi.Attributes["billingFirstName"] != null)
			{
				billingInfo.BillingFirstName = nodebi.Attributes["billingFirstName"].Value;
			}

			if (nodebi.Attributes["billingLastName"] != null)
			{
				billingInfo.BillingLastName = nodebi.Attributes["billingLastName"].Value;
			}

			if (nodebi.Attributes["billingPostalCode"] != null)
			{
				billingInfo.BillingPostalCode = nodebi.Attributes["billingPostalCode"].Value;
			}

			if (nodebi.Attributes["billingStreetAddress"] != null)
			{
				billingInfo.BillingStreetAddress = nodebi.Attributes["billingStreetAddress"].Value;
			}

			if (nodebi.Attributes["billingStreetAddress2"] != null)
			{
				billingInfo.BillingStreetAddress2 = nodebi.Attributes["billingStreetAddress2"].Value;
			}

			if (nodebi.Attributes["billingCompany"] != null)
			{
				String companyId  = nodebi.Attributes["billingCompany"].Value;
				billingInfo.Company = Facade.Instance.ModelFactory.CreateCompany();
				billingInfo.Company.Id = companyId;
			}
		}


		public override object GetContext()
		{
			return billingInfo;
		}
	}
}
